<!DOCTYPE html>
<html lang="en">
	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta charset="utf-8">
		<title>产品关联-商品关联</title>
		<meta name="description" content="overview &amp; stats">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
		<!-- bootstrap & fontawesome -->
		<link rel="stylesheet" href="${request.contextPath}/static/assets/css/bootstrap.css">
		<link rel="stylesheet" href="${request.contextPath}/static/assets/font-awesome/4.5.0/css/font-awesome.min.css">
		<!-- page specific plugin styles -->
		<link rel="stylesheet" href="${request.contextPath}/static/assets/css/daterangepicker.min.css">
		<link rel="stylesheet" href="${request.contextPath}/static/assets/css/jquery.css">
		<!-- text fonts -->
		<link rel="stylesheet" href="${request.contextPath}/static/assets/css/fonts.css">
		<!-- ace styles -->
		<link rel="stylesheet" href="${request.contextPath}/static/assets/css/ace.min.css" class="ace-main-stylesheet" id="main-ace-style">
		<link rel="stylesheet" href="${request.contextPath}/static/assets/css/ace-skins.min.css">
		<link rel="stylesheet" href="${request.contextPath}/static/assets/css/ace-rtl.min.css">
		<!-- ace settings handler -->
		<script src="${request.contextPath}/static/assets/js/ace-extra.min.js"></script><style>@keyframes nodeInserted{from{outline-color:#fff}to{outline-color:#000}}@-moz-keyframes nodeInserted{from{outline-color:#fff}to{outline-color:#000}}@-webkit-keyframes nodeInserted{from{outline-color:#fff}to{outline-color:#000}}@-ms-keyframes nodeInserted{from{outline-color:#fff}to{outline-color:#000}}@-o-keyframes nodeInserted{from{outline-color:#fff}to{outline-color:#000}}.ace-save-state{animation-duration:10ms;-o-animation-duration:10ms;-ms-animation-duration:10ms;-moz-animation-duration:10ms;-webkit-animation-duration:10ms;animation-delay:0s;-o-animation-delay:0s;-ms-animation-delay:0s;-moz-animation-delay:0s;-webkit-animation-delay:0s;animation-name:nodeInserted;-o-animation-name:nodeInserted;-ms-animation-name:nodeInserted;-moz-animation-name:nodeInserted;-webkit-animation-name:nodeInserted}</style>
		<script src="${request.contextPath}/static/assets/js/jquery-2.1.4.min.js"></script>	
		<link rel="stylesheet" href="${request.contextPath}/static/assets/css/bsie-paginator.css">
		<style type="text/css">
			#deleteRemind{
				width:500px
			}
			#linkCommodityModal{
				width:850px
			}
			::-webkit-scrollbar{ display: none;}
		</style>
	</head>

	<body class="skin-2" style="background-color: #FFF;">
		<div class="page-content" style="padding: 2px 2px 0px;">
		  <div class="tabbable">
			<div class="tab-content">
				<div id="manage" class="tab-pane active in">
					<!-- 筛选条件开始 -->
					<div class="row">
						<div class="col-sm-12">
							<div style="padding-right: 10px;">
								<span class="label label-xlg label-purple arrowed"  style="cursor: pointer;"   onclick="skip('${request.contextPath}/datashow/list?page=<#if prodPageNum??>${prodPageNum}<#else>1</#if>&productId=${productConditionVO.productId!}&sceneryName=${productConditionVO.sceneryName!}&cityCode=${productConditionVO.cityCode!}&starLevel=${productConditionVO.starLevel!}&businessCode=${productConditionVO.businessCode!}');">返回</span>
							</div>
							<div class="widget-box">
								<div class="widget-header">
									<h4 class="widget-title lighter">
										<i class="ace-icon fa"></i><#if sceneryName??>${sceneryName}</#if>
									</h4>
									</div>
								<form class="form-inline" id="searchForm" action="${request.contextPath}/datashow/product_list?productId=<#if commConditionVO??&&commConditionVO.productId??>${commConditionVO.productId}</#if>&sceneryName=${sceneryName!}&prodPageNum=${prodPageNum!}&productIdVO=${productConditionVO.productId!}&sceneryNameVO=${productConditionVO.sceneryName!}&cityCode=${productConditionVO.cityCode!}&starLevel=${productConditionVO.starLevel!}&businessCode=${productConditionVO.businessCode!}" method="post">
									<input type="hidden" id="_csrf" name="${_csrf.parameterName}" value="${_csrf.token}"/>
								</form>
						</div>
					</div>
					<!-- 筛选条件结束 -->
				    <!-- tab开始 -->
					 <div class="col-xs-12"  id="codeList">
					 	<input type="hidden" id="_csrf" name="${_csrf.parameterName}" value="${_csrf.token}"/>
						<input id="productId" name="productId" value="<#if commConditionVO??&&commConditionVO.productId??>${commConditionVO.productId}</#if>" type="hidden">
						<input id="sceneryName" name="sceneryName" value="<#if sceneryName??>${sceneryName}</#if>" type="hidden">
						<input id="businessCode" name="businessCode" value="<#if productConditionVO??&&productConditionVO.businessCode??>${productConditionVO.businessCode}</#if>" type="hidden">
						<input type="hidden" name="test_word" value="<#if relevanceProduct?? && relevanceProduct.prodIdMT??>${relevanceProduct.prodIdMT}</#if>">
						<input type="hidden" name="cityCode" id="cityCode" value="<#if productConditionVO?? && productConditionVO.cityCode??>${productConditionVO.cityCode}</#if>">
						<#if relevanceProduct??>
						<table id="dynamic-table" class="table table-striped table-bordered table-hover dataTable no-footer" role="grid" aria-describedby="dynamic-table_info">
							<thead>
								<tr>
									<th>No.</th>
									<th>商品id</th>
									<#if productConditionVO??&&productConditionVO.businessCode??&&productConditionVO.businessCode=="HOTEL"><th>商品类型</th></#if>
									<th>商品名称</th>
									<th>商品价格</th>
									<#if relevanceProduct.prodIdXC??>
									<th>XC</th>
									</#if>
									<#if relevanceProduct.prodIdTN??>
									<th>TN</th>
									</#if>
									<#if relevanceProduct.prodIdTC??>
									<th>TC</th>
									</#if>
									<#if relevanceProduct.prodIdEL??>
									<th>EL</th>
									</#if>
									<#if relevanceProduct.prodIdQNR??>
									<th>QNR</th>
									</#if>
									<#if relevanceProduct.prodIdMT?? &&productConditionVO.businessCode??&&productConditionVO.businessCode=="TICKET" ><!-- -->
										<th>MT</th>
									</#if>
								</tr>
							</thead>
							<tbody>
									<#if ptcs??&&ptcs?size&gt;0>
									<#list ptcs as comm>
									
									<tr class="">
										<td>${comm_index + 1}</td>
										<td class="tdCommodityId"><#if comm.commodity_id??>${comm.commodity_id}</#if></td>
										<#if comm.commodity_type??><td class="commodityType">${comm.commodity_type}</td></#if>
										<td class="tdCommodityName"><#if comm.commodity_name??>${comm.commodity_name}</#if></td>
										<td class="commodityPrice"><#if comm.commodity_price??>￥${comm.commodity_price}</#if></td>
										<#if relevanceProduct.prodIdXC??>
										<td class="xc" id="xc_<#if comm.commodity_id??>${comm.commodity_id}</#if>">
											<span class="relevanceCommodity">
												<#if comm.commodity_id_xc??><span id="${comm.commodity_id_xc}_xc">${comm.commodity_name_xc!}</span></#if>
											</span>
											<span class="hidden-sm hidden-xs action-buttons" style="float:right;cursor:pointer;">
												<a class="green" onclick="linkCommodity(this);" role="button">
													<i class="ace-icon fa fa-pencil bigger-130"></i>
												</a>
												<a class="red" onclick="deleteCommodity(this);" role="button" data-toggle="modal" data-target="#deleteModal">
													<i class="ace-icon fa fa-trash-o bigger-130"></i>
												</a>
											</span>
										</td>
										</#if>
										<#if relevanceProduct.prodIdTN??>
										<td class="tn" id="tn_<#if comm.commodity_id??>${comm.commodity_id}</#if>">
											<span class="relevanceCommodity">
												<#if comm.commodity_id_tn??><span id="${comm.commodity_id_tn}_tn">${comm.commodity_name_tn!}</span></#if>
											</span>
											<span class="hidden-sm hidden-xs action-buttons" style="float:right;cursor:pointer;">
												<a class="green" onclick="linkCommodity(this);" role="button">
													<i class="ace-icon fa fa-pencil bigger-130"></i>
												</a>
												<a class="red" onclick="deleteCommodity(this);" role="button" data-toggle="modal" data-target="#deleteModal">
													<i class="ace-icon fa fa-trash-o bigger-130"></i>
												</a>
											</span>
										</td>
										</#if>
										<#if relevanceProduct.prodIdTC??>
										<td class="tc" id="tc_<#if comm.commodity_id??>${comm.commodity_id}</#if>">
											<span class="relevanceCommodity" >
												<#if comm.commodity_id_tc??><span id="${comm.commodity_id_tc}_tc">${comm.commodity_name_tc!}</span></#if>
											</span>
											<span class="hidden-sm hidden-xs action-buttons" style="float:right;cursor:pointer;">
												<a class="green" onclick="linkCommodity(this);" role="button">
													<i class="ace-icon fa fa-pencil bigger-130"></i>
												</a>
												<a class="red" onclick="deleteCommodity(this);" role="button" data-toggle="modal" data-target="#deleteModal">
													<i class="ace-icon fa fa-trash-o bigger-130"></i>
												</a>
											</span>
										</td>
										</#if>
										<#if relevanceProduct.prodIdEL??>
										<td class="el" id="el_<#if comm.commodity_id??>${comm.commodity_id}</#if>">
											<span class="relevanceCommodity" >
												<#if comm.commodity_id_el??><span id="${comm.commodity_id_el}_el">${comm.commodity_name_el!}</span></#if>
											</span>
											<span class="hidden-sm hidden-xs action-buttons" style="float:right;cursor:pointer;">
												<a class="green" onclick="linkCommodity(this);" role="button">
													<i class="ace-icon fa fa-pencil bigger-130"></i>
												</a>
												<a class="red" onclick="deleteCommodity(this);" role="button" data-toggle="modal" data-target="#deleteModal">
													<i class="ace-icon fa fa-trash-o bigger-130"></i>
												</a>
											</span>
										</td>
										</#if>
										<#if relevanceProduct.prodIdQNR??>
										<td class="qnr" id="qnr_<#if comm.commodity_id??>${comm.commodity_id}</#if>">
											<span class="relevanceCommodity" align="left">
												<#if comm.commodity_id_qnr??><span id="${comm.commodity_id_qnr}_qnr">${comm.commodity_name_qnr!}</span></#if>
											</span>
											<span class="hidden-sm hidden-xs action-buttons" style="float:right;cursor:pointer;">
												<a class="green" onclick="linkCommodity(this);" role="button">
													<i class="ace-icon fa fa-pencil bigger-130"></i>
												</a>
												<a class="red" onclick="deleteCommodity(this);" role="button" data-toggle="modal" data-target="#deleteModal">
													<i class="ace-icon fa fa-trash-o bigger-130"></i>
												</a>
											</span>
										</td>
										</#if>
										<!-- 增加美团-->
										<#if relevanceProduct.prodIdMT?? &&productConditionVO.businessCode??&&productConditionVO.businessCode=="TICKET">
											<td class="mt" id="mt_<#if comm.commodity_id??>${comm.commodity_id}</#if>">
											<span class="relevanceCommodity" align="left">
												<#if comm.commodity_id_mt??><span id="${comm.commodity_id_mt}_mt">${comm.commodity_name_mt!}</span></#if>
											</span>
												<span class="hidden-sm hidden-xs action-buttons" style="float:right;cursor:pointer;">
												<a class="green" onclick="linkCommodity(this);" role="button">
													<i class="ace-icon fa fa-pencil bigger-130"></i>
												</a>
												<a class="red" onclick="deleteCommodity(this);" role="button" data-toggle="modal" data-target="#deleteModal">
													<i class="ace-icon fa fa-trash-o bigger-130"></i>
												</a>
											</span>
											</td>
										</#if>
									</tr>
									
									</#list>
									</#if>

							</tbody>
						</table>
						</#if>
						<#include "paginator.html">
				</div>
			</div>
		</div>
	</div>
	</div>
	</div>
		
		
		
		
		<div class="row">
			<div class="col-xs-12">
				<button class="btn btn-info" data-toggle="modal" type="button" style="display:none;" id="update" data-target="#myModal">
				</button>
				<form id="linkCommodity" class="form-horizontal" role="form">
					<input type="hidden" id="companyCode" name="companyCode"/>
					<input type="hidden" id="commodityId" name="commodityId"/>
					<input type="hidden" id="commodityName" name="commodityName"/>
					
				<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
					   <div class="modal-dialog" id="linkCommodityModal">
					      <div class="modal-content">
					         <div class="modal-header">
					            <button type="button" class="close" data-dismiss="modal" aria-hidden="true" id="update">
					                  ×
					            </button>
					            <h4 class="modal-title" id="myModalLabel">
					               	关联商品
					            </h4>
					         </div>
				         <div class="modal-body">
							<div class="form-group">
								<label class="col-sm-3 control-label no-padding-right" for="form-field-1"> <strong class="text-danger">*</strong>商品名称 </label>
								<div class="col-sm-8">
									<input id="selectCommodityName" name="selectCommodityName" class="col-xs-10 col-sm-8" type="text" placeholder="模糊查询景点名称">
									
									<div class="dataTables_length"><!--- 查询商品 --->
										<button class="btn btn-pink btn-sm" type="button" id="select">
											<span class="ace-icon fa fa-search icon-on-right bigger-90"></span>
											查询
										</button>
									</div>					
								</div>
								<div class="col-sm-9" id="commodityInfo"></div>
									<!--  <label class="col-sm-2 control-label no-padding-left" for="form-field-1"> <strong class="text-danger">*</strong>商品名称 </label>
									<input id="productId" name="productId" value="<#if commConditionVO??&&commConditionVO.productId??>${commConditionVO.productId}</#if>" type="hidden">
									<label><input name="cname" type="radio" value="" />	上海迪士尼乐园成人票(凭身份证入园) </label> -->
								</div>
				         </div>
				         <div class="modal-footer">
				            <button type="button" class="btn btn-default" data-dismiss="modal">关闭
				            </button>
				            <button id="save" type="button" onclick="saveLink(this);" class="btn btn-primary" data-dismiss="modal">
				              	 关联
				            </button>
				         </div>
				      </div><!-- /.modal-content -->
					</div><!-- /.modal -->
				</div>
				</form>
				
				<!-- 删除提醒 -->
				<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel" aria-hidden="true">
				<input type="hidden" id="relCommodityId" name="relCommodityId"/>
				<input type="hidden" id="delCommodityId" name="delCommodityId"/>
				<input type="hidden" id="delCompanyCode" name="delCompanyCode"/>
				<div class="modal-dialog link" id="deleteRemind">
					<div class="modal-content">
						<div class="modal-header" style="height:50px">
				            <button type="button" class="close" data-dismiss="modal" aria-hidden="true" id='close1' style="height:10px;line-height:1px">
				                  <small>×</small>
				            </button>
				            <span style="height:10px;line-height:5px;font-size:15px" id="deleteTitle">是否确认删除关联？</span>
			         	</div>
			         	<div class="modal-body">
			         			 <strong style="padding-left:120px">是否确认删除关联？</strong>
			         	</div>
			         	<div class="modal-footer" style="height:50px">
			         		<button type="button" class="btn btn-default" data-dismiss="modal" style="height:30px;line-height:10px">
						    	取消
						    </button>
			         		<button type="button"  class="btn btn-primary" data-dismiss="modal" style="height:30px;line-height:10px" id="confirmDelete">
				              	 确定
				            </button>
			         	</div>
					</div>
				</div>
			</div>
				
			</div>
		</div>
		<input type="hidden" id="productlistcontext" value="${request.contextPath}"/>
		<script type="text/javascript">
			if('ontouchstart' in document.documentElement) 
				document.write("<script src='${request.contextPath}/static/assets/js/jquery.mobile.custom.min.js'>"+"<"+"/script>");
		</script>
			
		<script src="${request.contextPath}/static/assets/js/bootstrap.min.js"></script>
		<script src="${request.contextPath}/static/assets/js/jquery-ui.min.js"></script>
		<script src="${request.contextPath}/static/assets/js/bootbox.js"></script>
		<script src="${request.contextPath}/static/assets/js/spin.js"></script>
		<!-- ace scripts -->
		<script src="${request.contextPath}/static/assets/js/ace-elements.min.js"></script>
		<script src="${request.contextPath}/static/assets/js/ace.min.js"></script>
		<!-- validator scripts -->
		<script src="${request.contextPath}/static/assets/js/bootstrapValidator.min.js"></script>
		<!-- user scripts -->
		<script src="${request.contextPath}/static/assets/js/user/base.js"></script>
		<script type="text/javascript">
			/**
			* Vertically center Bootstrap 3 modals so they aren't always stuck at the top
			*/
			$(function() {
			function reposition() {
			var modal = $(this),
			dialog = modal.find('.modal-dialog');
			modal.css('display', 'block');
	
			// Dividing by two centers the modal exactly, but dividing by three
			// or four works better for larger screens.
			dialog.css("margin-top", Math.max(0, ($(window).height() - dialog.height()) / 5));
			}
			// Reposition when a modal is shown
			$('.modal').on('show.bs.modal', reposition);
			// Reposition when the window is resized
			$(window).on('resize', function() {
			$('.modal:visible').each(reposition);
			});
			});
		</script>
		<script type="text/javascript">
			$("#myModal").draggable();
			$("#deleteModal").draggable();
			var productlistcontext = $("#productlistcontext").val();
			var linkCommodity = function(obj){
				companyCode=$(obj).parents("td").attr("class").trim();
				commodityName=$(obj).parents("tr").find(".tdCommodityName").text().trim();
				commodityPrice=$(obj).parents("tr").find(".commodityPrice").text().trim();
				commodityId=$(obj).parents("tr").find(".tdCommodityId").text().trim();
				productId=$("#productId").val().trim();
                cityCode=$("#cityCode").val().trim();
				$("#companyCode").val(companyCode);
				$("#commodityName").val(commodityName);
				$("#commodityId").val(commodityId);
				businessCode=$("#businessCode").val();
				$.ajax({
					url : productlistcontext+'/datashow/selectCommodity',
					type : "GET",
					data : {
						companyCode:companyCode,
						productId:productId,
						businessCode:businessCode,
                        lvmamaCommodityId:commodityId,//新增传入驴妈妈商品ID
                        cityCode:cityCode//新增城市编码
					},
					success:function(data){
						if(data.sessionStatus==540){//异步请求session过期状态
							window.location.href=productlistcontext+"/login";
							return;
						}else{
							//先去掉之前的内容，以免页面中有重复值
							$("#commodityInfo div").remove();
							$("#myModalLabel").text("");
							$("#myModalLabel").text("关联商品："+commodityName+"（"+commodityPrice+"）");
							//$("#selectCommodityName").val(commodityName);
							$("#update").click();
							commodityData=data.commodityItems;
							hotelCommodityData=data.commoditys;
							if(commodityData!=null&&commodityData.length>0){
								var table="<div style='height:400px;width:800px;overflow:auto'><table class='table table-striped table-bordered table-hover dataTable no-footer' style='width: 800px'>";
								thead="<thead><th>商品id</th><th>商品名称</th> <th>商品价格</th> <th>状态</th></thead>";
								table+=thead;
								tbody="";
								
								$.each(commodityData,function(n,value) {
									
									var trs = ""; 
									trs += " <tr><td class='comCommodityId'> " +value.commodity_id+" </td> <td class='comCommodityName'>" + value.commodity_name +"</td> <td>￥"+value.sale_price+"</td>"; 
									if(value.is_link==1){
										trs+="<td style='color:red'>已关联</td></tr>";
									}else{
										trs+= "<td><input name='comCommodityName' type='radio'/></td></tr>";
									}
								    tbody += trs;
								});
								table+=tbody;
								table+="</table></div>";
							     $("#commodityInfo").append(table);
								
							}else if(hotelCommodityData!=null&&hotelCommodityData.length>0){
								var table="<div style='height:400px;width:800px;overflow:auto'><table class='table table-striped table-bordered table-hover dataTable no-footer' style='width: 800px'>";
								thead="<thead><th>商品id</th><th>房型</th><th>商品名称</th> <th>商品价格</th> <th></th></thead>";
								table+=thead;
								tbody="";
								
								$.each(hotelCommodityData,function(n,value) {
									
									var trs = ""; 
									trs += " <tr><td class='comCommodityId'> " +value.commodityId+" </td><td class='comCommodityType'>"+value.roomType+"</td> <td class='comCommodityName'>" + value.commodityName +"</td> <td>￥"+value.salePrice+"</td>";
//									trs += " <tr><td class='comCommodityId'> " +value.commodityId+" </td><td class='comCommodityType'>"+value.commodityType+"</td> <td class='comCommodityName'>" + value.commodityName +"</td> <td>￥"+value.salePrice+"</td>";
									if(value.isLink==1){
										trs+="<td style='color:red'>已关联</td></tr>";
									}else{
										trs+= "<td><input name='comCommodityName' type='radio'/></td></tr>";
									}
								    tbody += trs;
								});
								table+=tbody;
								table+="</table></div>";
							     $("#commodityInfo").append(table);
							}else{
								$("#commodityInfo").append("<div style='color:red' align='center'><strong style='font-size:15px'>没有可关联的商品！</strong></div>");
								
							}
						}
						
					}
				});
			};
			
			$("#select").click(function(){
				companyCode=$("#companyCode").val().trim();
				productId=$("#productId").val().trim();
				commodityName=$("#selectCommodityName").val().trim();
				businessCode=$("#businessCode").val();
                cityCode=$("#cityCode").val().trim();
                commodityId=$("#commodityId").val().trim();
                $.ajax({
					url : productlistcontext+'/datashow/selectCommodity',
					type : "GET",
					data : {
						companyCode:companyCode,
						productId:productId,
						commodityName:commodityName,
						businessCode:businessCode,
                        cityCode:cityCode,
                        lvmamaCommodityId:commodityId
					},
					success:function(data){
						if(data.sessionStatus==540){//异步请求session过期状态
							window.location.href=productlistcontext+"/login";
							return;
						}else{
							//先去掉之前的内容，以免页面中有重复值
							$("#commodityInfo div").remove();
							
							commodityData=data.commodityItems;
							hotelCommodityData=data.commoditys;
							if(commodityData!=null&&commodityData.length>0){
							    <!-- 此处增加房型保持原来结构不变 -->
								var table="<div style='height:400px;width:800px;overflow:auto'><table class='table table-striped table-bordered table-hover dataTable no-footer' style='width: 800px'>";
								thead="<thead><th>商品id</th><th>商品名称</th> <th>商品价格</th> <th>状态</th></thead>";
								table+=thead;
								tbody="";
								
								$.each(commodityData,function(n,value) {
									
									var trs = ""; 
									trs += " <tr><td class='comCommodityId'> " +value.commodity_id+" </td> <td class='comCommodityName'>" + value.commodity_name +"</td> <td>￥"+value.sale_price+"</td>"; 
									if(value.is_link==1){
										trs+="<td style='color:red'>已关联</td></tr>";
									}else{
										trs+= "<td><input name='comCommodityName' type='radio'/></td></tr>";
									}
								    tbody += trs;
								});
								table+=tbody;
								table+="</table></div>";
							     $("#commodityInfo").append(table);
								
							}else if(hotelCommodityData!=null&&hotelCommodityData.length>0){
								var table="<div style='height:400px;width:800px;overflow:auto'><table class='table table-striped table-bordered table-hover dataTable no-footer' style='width: 800px'>";
								thead="<thead><th>商品id</th><th>房型</th><th>商品名称</th> <th>商品价格</th> <th></th></thead>";
								table+=thead;
								tbody="";
								
								$.each(hotelCommodityData,function(n,value) {
									
									var trs = ""; 
									trs += " <tr><td class='comCommodityId'> " +value.commodityId+" </td><td class='comCommodityType'>"+value.roomType+"</td> <td class='comCommodityName'>" + value.commodityName +"</td> <td>￥"+value.salePrice+"</td>"; 
									if(value.isLink==1){
										trs+="<td style='color:red'>已关联</td></tr>";
									}else{
										trs+= "<td><input name='comCommodityName' type='radio'/></td></tr>";
									}
								    tbody += trs;
								});
								table+=tbody;
								table+="</table></div>";
							     $("#commodityInfo").append(table);
							}else{
								$("#commodityInfo").append("<div style='color:red' align='center'><strong style='font-size:15px'>没有可关联的商品！</strong></div>");
								
							}
						}
						
					}
				});
				
			});
			var saveLink=function(obj){
				var display=$("#commodityInfo div table").css("display");
				 if($('input:radio').is(':checked')&& display!="none"){
					 comCommodityId=$('input:radio:checked').parents("tr").find(".comCommodityId").text().trim();
					 comCommodityName=$('input:radio:checked').parents("tr").find(".comCommodityName").text().trim();
					 prodId=$("#productId").val().trim();
					 commodityId=$("#commodityId").val().trim();
					 companyCode=$("#companyCode").val().trim();
					 businessCode=$("#businessCode").val();
					 $.ajax({
						url : productlistcontext+'/datashow/linkCommodity',
						type : "GET",
						data : {
							company_code:companyCode,
							prod_id:prodId,
							commodity_id:commodityId,
							rel_commodity_id:comCommodityId,
							rel_commodity_name:comCommodityName,
							businessCode:businessCode
						},
						beforSend:function(){
							$("#save").attr("onclick","javascript:void();");
						},
						success:function(data){
							if(data.sessionStatus==540){//异步请求session过期状态
								window.location.href=productlistcontext+"/login";
								return;
							}else{
								comId=companyCode+"_"+commodityId;
								relCommodityId=comCommodityId+"_"+companyCode;
								$("#"+comId).find(".relevanceCommodity").text("");
								$("#"+comId).find(".relevanceCommodity").append("<span id='"+relCommodityId+"'>"+comCommodityName+"</span>");
								$("#commodityInfo div").remove(); 
								$("#"+comId).find("a.green").hide();
								$("#"+comId).find("a.red").show();
							}
							
						},
						complete:function(){
							$("#save").attr("onclick","saveLink(this);");
						},
					});
				}else{
					bootbox.alert("<strong style='padding-left:200px;font-size:15px'>请选择要关联的商品！</strong>");
				}
			};
			
			$("#close1").click(function(){
				$("#commodityInfo div").hide();
			});
			$("#close2").click(function(){
				$("#commodityInfo div").hide();
			});
			var deleteCommodity=function(obj){
				relevanceCommodity=$(obj).parents("td").find(".relevanceCommodity span");
				relCommodityId=relevanceCommodity.attr("id");
				companyCode=relevanceCommodity.parents('td').attr("class").trim();
				commodityId=relevanceCommodity.parents('td').attr("id").split("_")[1].trim();
				tdCommodityName=$(obj).parents("td").find(".relevanceCommodity span").text();
				
				$("#relCommodityId").val(relCommodityId);
				$("#delCompanyCode").val(companyCode);
				$("#delCommodityId").val(commodityId);
				$("#deleteTitle").text("");
				$("#deleteTitle").text(tdCommodityName);
				/*
				bootbox.confirm("<strong style='font-size:15px;padding-left:200px'>是否确认删除关联？</strong>", function(result){
				if(result){
					//ajax返回信息到后台删除关联信息
					relevanceCommodity=$(obj).parents("td").find(".relevanceCommodity div");
					relCommodityId=relevanceCommodity.attr("id");
					alert(relCommodityId);
					companyCode=relevanceCommodity.parents('td').attr("class").trim();
					
					commodityId=relevanceCommodity.parents('td').attr("id").split("_")[1].trim();
					prodId=$("#productId").val().trim();
					$.ajax({
						url : '/datashow/deleteCommodity',
						type : "GET",
						data : {
							company_code:companyCode,
							prod_id:prodId,
							rel_commodity_id:relCommodityId,
							commodity_id:commodityId
						},
						success:function(data){
							$(obj).parent().parents('td').find(".relevanceCommodity div").text("");
							//$(obj).parent().parents('td').find(".relevanceCommodity div").attr('id')="";
							$(obj).hide();
							$(obj).prev().show();
						}
					});
				}*/
				//});
				}
				$("#confirmDelete").click(function(){
					relCommodityId=$("#relCommodityId").val().split("_")[0];
					companyCode=$("#delCompanyCode").val();
					commodityId=$("#delCommodityId").val();
					prodId=$("#productId").val().trim();
					businessCode=$("#businessCode").val();
					$.ajax({
						url : productlistcontext+'/datashow/deleteCommodity',
						type : "GET",
						data : {
							company_code:companyCode,
							prod_id:prodId,
							rel_commodity_id:relCommodityId,
							commodity_id:commodityId,
							businessCode:businessCode
						},
						success:function(data){
							if(data.sessionStatus==540){//异步请求session过期状态
								window.location.href=productlistcontext+"/login";
								return;
							}else{
								$("#"+relCommodityId+"_"+companyCode).parents("td").find("a.green").show();
								$("#"+relCommodityId+"_"+companyCode).parents("td").find("a.red").hide();
								$("#"+relCommodityId+"_"+companyCode).remove();
							}
							
						}
					});
				})
		
			$(".relevanceCommodity").each(function(index,data){ 
				if ($(data).text().trim()!=""){
					$(data).next().find("a.green").hide();
				}else{
					$(data).next().find("a.red").hide();
				}
			});
		
		</script>
	
	</body>
</html>